import Cookies from 'js-cookie'
export const state = () => {
    return {
        token: null
    }
}
export const actions = {
    nuxtServerInit({ commit }, { req }) {
        if (req.headers.cookie) {
            let cookie = req.headers.cookie.split(";");
            commit('getCookie', {
                ar: cookie,
                n: 'token'
            })
        }
    }
}
export const mutations = {
    getCookie(state, data) {
        for (let i = 0; i < data.ar.length; i++) {
            if (data.ar[i].indexOf(data.n) !== -1) {
                state.token = data.ar[i].split(data.n + "=")[1];
            }
        }
    },
    // 获取用户信息
    getUserInfo(state, data) {
        state.token = data;
        Cookies.set('token', data);
    }
}